home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Marlais / Marlais 0.5.9-portable sources / slot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  4.7 KB  |  227 lines  |  [TEXT/ttxt]

  1. /*
  2.  
  3.    slot.c
  4.  
  5.    This software is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This software is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public
  16.    License along with this software; if not, write to the Free
  17.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.    Original copyright notice follows:
  20.  
  21.    Copyright, 1993, Brent Benson.  All Rights Reserved.
  22.    0.4 & 0.5 Revisions Copyright 1994, Joseph N. Wilson.  All Rights Reserved.
  23.  
  24.    Permission to use, copy, and modify this software and its
  25.    documentation is hereby granted only under the following terms and
  26.    conditions.  Both the above copyright notice and this permission
  27.    notice must appear in all copies of the software, derivative works
  28.    or modified version, and both notices must appear in supporting
  29.    documentation.  Users of this software agree to the terms and
  30.    conditions set forth in this notice.
  31.  
  32.  */
  33.  
  34. #include "slot.h"
  35.  
  36. #include "apply.h"
  37. #include "class.h"
  38. #include "error.h"
  39. #include "eval.h"
  40. #include "globaldefs.h"
  41. #include "keyword.h"
  42. #include "list.h"
  43. #include "prim.h"
  44. #include "vector.h"
  45.  
  46. /* primitives */
  47. static Object instance_slots (Object instance);
  48. static Object class_slots (Object class);
  49.  
  50. static struct primitive slot_prims[] =
  51. {
  52.     {"slot-value", prim_2, slot_value},
  53.     {"set-slot-value!", prim_3, set_slot_value},
  54.     {"%instance-slots", prim_1, instance_slots},
  55.     {"%class-slots", prim_1, class_slots},
  56. };
  57.  
  58. /* function definitions */
  59.  
  60. void
  61. init_slot_prims (void)
  62. {
  63.     int num;
  64.  
  65.     num = sizeof (slot_prims) / sizeof (struct primitive);
  66.  
  67.     init_prims (num, slot_prims);
  68. }
  69.  
  70.  
  71. Object
  72. make_slot_descriptor (unsigned char properties, Object getter, Object setter,
  73.               Object type, Object init, Object init_keyword,
  74.               Object allocation, Object dynamism)
  75. {
  76.     Object obj;
  77.  
  78.     obj = allocate_object (sizeof (struct slot_descriptor));
  79.  
  80.     SLOTDTYPE (obj) = SlotDescriptor;
  81.     SLOTDPROPS (obj) = properties;
  82.     SLOTDGETTER (obj) = getter;
  83.     SLOTDSETTER (obj) = setter;
  84.     SLOTDSLOTTYPE (obj) = type;
  85.     SLOTDINIT (obj) = init;
  86.     SLOTDINITKEYWORD (obj) = init_keyword;
  87.     SLOTDALLOCATION (obj) = allocation;
  88.     SLOTDDYNAMISM (obj) = dynamism;
  89.  
  90.     return obj;
  91. }
  92.  
  93. Object
  94. slot_name (Object slot)
  95. {
  96.     if (!PAIRP (slot)) {
  97.     return (slot);
  98.     } else {
  99.     if (SYMBOLP (CAR (slot))) {
  100.         return (CAR (slot));
  101.     } else {
  102.         error ("Slot has no name but needs one", slot, NULL);
  103.         return NULL;
  104.     }
  105.     }
  106. }
  107.  
  108. Object
  109. slot_getter (Object slot)
  110. {
  111.     Object get_list;
  112.  
  113.     if (!PAIRP (slot)) {
  114.     return (NULL);
  115.     } else {
  116.     return (find_keyword_val (getter_keyword, slot));
  117.     }
  118. }
  119.  
  120. Object
  121. slot_setter (Object slot)
  122. {
  123.     Object set_list;
  124.  
  125.     if (!PAIRP (slot)) {
  126.     return (NULL);
  127.     } else {
  128.     return (find_keyword_val (setter_keyword, slot));
  129.     }
  130. }
  131.  
  132. Object
  133. slot_type (Object slot)
  134. {
  135.     Object type_list;
  136.  
  137.     if (!PAIRP (slot)) {
  138.     return (NULL);
  139.     } else {
  140.     return (find_keyword_val (type_keyword, slot));
  141.     }
  142. }
  143.  
  144. Object
  145. slot_init_value (Object slotd)
  146. {
  147.     if (SLOTDINITFUNCTION (slotd)) {
  148.     return eval (cons (listem (quote_symbol, SLOTDINIT (slotd), NULL),
  149.                make_empty_list ()));
  150.     } else {
  151.     return SLOTDINIT (slotd);
  152.     }
  153. }
  154.  
  155. Object
  156. slot_init_function (Object slot)
  157. {
  158.     Object init_list;
  159.  
  160.     if (!PAIRP (slot)) {
  161.     return (NULL);
  162.     } else {
  163.     return (find_keyword_val (init_function_keyword, slot));
  164.     }
  165. }
  166.  
  167. Object
  168. slot_init_keyword (Object slot)
  169. {
  170.     Object init_list;
  171.  
  172.     if (!PAIRP (slot)) {
  173.     return (NULL);
  174.     } else {
  175.     return (find_keyword_val (init_keyword_keyword, slot));
  176.     }
  177. }
  178.  
  179. Object
  180. slot_required_init_keyword (Object slot)
  181. {
  182.     Object init_list;
  183.  
  184.     if (!PAIRP (slot)) {
  185.     return (NULL);
  186.     } else {
  187.     return (find_keyword_val (required_init_keyword_keyword, slot));
  188.     }
  189. }
  190.  
  191. Object
  192. slot_allocation (Object slot)
  193. {
  194.     Object alloc_list;
  195.  
  196.     if (!PAIRP (slot)) {
  197.     return (NULL);
  198.     } else {
  199.     return (find_keyword_val (allocation_keyword, slot));
  200.     }
  201. }
  202.  
  203. Object
  204. slot_value (Object instance, Object slot_num)
  205. {
  206.     return CAR (INSTSLOTS (instance)[INTVAL (slot_num)]);
  207. }
  208.  
  209. Object
  210. set_slot_value (Object instance, Object slot_num, Object val)
  211. {
  212.     CAR (INSTSLOTS (instance)[INTVAL (slot_num)]) = val;
  213.     return val;
  214. }
  215.  
  216. static Object
  217. instance_slots (Object instance)
  218. {
  219.     return (Object) (&INSTSLOTS (instance));
  220. }
  221.  
  222. static Object
  223. class_slots (Object class)
  224. {
  225.     return (Object) (CLASSCSLOTS (class));
  226. }
  227.